﻿
@{
    ViewData["Title"] = "QuitView";
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <title>离职办理</title>

    <link href="~/Content/bootstrap-theme.css" rel="stylesheet"/>
    <link href="~/layui/css/layui.css" rel="stylesheet"/>
    <link href="~/layer/skin/layer.css" rel="stylesheet"/>

    <style>
        body { margin: 10px; }

        .demo-carousel {
            height: 200px;
            line-height: 200px;
            text-align: center;
        }

        .layui-table-tool-self { display: none; }
    </style>

</head>
<body>
<div>
    <table>
            <tr>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择框</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-verify="required">
                                <option value="-1">全部</option>
                                <option value="0">待审批</option>
                                <option value="1">已同意</option>
                                <option value="2">已拒绝</option>
                            </select>
                        </div>
                    </div>
                </td>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">部  门：</label>
                        <div class="layui-input-block">
                            <select id="Department" name="Department" onchange="GetPositionInfoList()">
                            </select>     
                        </div>
                    </div>
                </td>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">职  位：</label>
                        <div class="layui-input-block">
                            <select id="Position" name="Position" lay-verify="">
                            </select>  
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">姓 名：</label>
                        <div class="layui-input-block">
                            <input type="text" id="name" name="name" placeholder="请输入姓名"  class="layui-input">
                        </div>
                    </div>
                </td>
                <td style="margin-left: 200px">
                    <div class="layui-form-item" style="margin-left: 200px">
                        <button id="Query" class="layui-btn layui-btn-radius layui-btn-normal">
                            <i class="layui-icon layui-icon-search"></i> 查询
                        </button>
                        <button onclick="Reset()"  class="layui-btn layui-btn-radius layui-btn-primary">
                            <i class="layui-icon layui-icon-return"></i> 重置
                        </button>
                    </div>
                </td>
            </tr>
            
        </table>
</div>
<table class="layui-hide" id="demo" lay-filter="test"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="SubmitInfo">提交</a>
</script>

<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="~/layui/layui.js"></script>
<script src="~/layer/layer.js"></script>
<script>

    //文档准备就绪函数
    $(function() {
        GetDeptinfoList();
    });

    //获取部门集合
    function GetDeptinfoList() {
        $.get("/PersonnelMatters/GetDeptinfoList",
            function(res) {
                var str = '<option value="0">请选择一个职位</option>';
                res.forEach(a => {
                    str+=(' <option value="' + a.id + '">' + a.name + '</option>');
                });
                $("#Department").append(str);
            });
        GetPositionInfoList();
    }
    

    //获取职业集合
    function GetPositionInfoList() {
        var id=$("#Department").val();
        $("#Position").empty();
        $.get("/PersonnelMatters/GetPositionInfoList?id="+id,
            function(res) {
                var str = '<option value="0">请选择一个职位</option>';
                res.forEach(a => {
                    str+=(' <option value="' + a.id + '">' + a.name + '</option>');
                });
                $("#Position").append(str);
            });
    }

    function Reset() {
        $("#name").val("");
        $("#state").val(-1);
        $("#Department").val(0);
        $("#Position").val(0);
    }


    layui.use(['laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'],
        function() {
            var layer = layui.layer, table = layui.table;
            table.render({
                elem: "#demo",
                height: 420,
                url: '/PersonnelMatters/GetDimissionList',
                title: '员工登记',
                toolbar: 'default', //头工具栏
                page: true,
                limit: 5,
                limits: [5, 10],
                cols: [
                    [//表头
                        { type: 'checkbox', fixed: 'left',name:"Ck" } //锁定第一列
                        , { field: 'saffName', title: '姓名', width: 100 },
                        { field: 'depName', title: '部门', width: 100 },
                        { field: 'postName', title: '职位', width: 100 },
                        { field: 'upName', title: '上级负责人', width: 110 },
                        { field: 'edate', title: '入职日期', width: 140, templet: "<div>{{layui.util.toDateString(d.create_time*1000, 'yyyy年MM月dd日 ')}}</div>" },
                        { field: 'dfinally', title: '最后工作日', width: 140, templet: "<div>{{layui.util.toDateString(d.create_time*1000, 'yyyy年MM月dd日 ')}}</div>" },
                        { field: 'dcause', title: '离职原因', width: 110 },
                        {
                            field: 'ezt',
                            title: '审批状态',
                            width: 100,
                            templet: function(d) {
                                return d.ezt===0?"待提交":d.ezt===1?"待审批":d.ezt===2?"已同意":"已拒绝";
                            }
                        },
                        { field: 'edatess', title: '创建时间', width: 140, templet: "<div>{{layui.util.toDateString(d.create_time*1000, 'yyyy年MM月dd日 ')}}</div>" },
                        { fixed: 'right', width: 180, align: 'center', toolbar: '#barDemo' }
                    ]
                ]

            });
            $("#Query").click(function(){
                var name = $("#name").val();
                var state = $("#state").val() == null ? -1: $("#state").val();
                var depId = $("#Department").val() == null ? 0 : $("#Department").val();
                var postId = $("#Position").val() == null ? 0 : $("#Position").val();
                table.reload('demo',
                    {
                        url: '/PersonnelMatters/GetDimissionList',
                        where: {
                            name: name,
                            state: state,
                            depId: depId,
                            postId: postId
                        },
                        page: {
                            curr: 1
                        }
                    });
            });

            //监听头工具栏事件
            table.on('toolbar',
                function(obj) {
                    var checkStatus = table.checkStatus(obj.config.id), data = checkStatus.data; //获取选中的数据
                    switch (obj.event) {
                    case 'add':
                        location.href = "/PersonnelMatters/AddDimissionView";
                        break;
                    case 'update':
                        if (data.length === 0) {
                            layer.msg('请选择一行');
                        } else if (data.length > 1) {
                            layer.msg('只能同时编辑一个');
                        } else {
                            location.href = "/PersonnelMatters/BackDimissionView?id=" +  checkStatus.data[0].id;
                        }
                        break;
                    case 'delete':
                        if (data.length === 0) {
                            layer.msg('请选择一行');
                        } else {
                            var ids = [];
                            for (var i = 0; i < checkStatus.data.length; i++) {
                                ids.push(checkStatus.data[i].id);
                            }
                            console.log(checkStatus.data);
                            $.post("/PersonnelMatters/DelDimission?id=" + ids.toString(),
                                function(res) {
                                    if (res > 0) {
                                        layer.msg("删除成功!");
                                        location.reload();
                                    } else {
                                        layer.msg("删除失败!");
                                    }
                                });
                        }
                        break;
                    };
                });


            //监听行工具事件
            table.on('tool(test)',
                function(obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                    var data = obj.data; //获得当前行数据,
                    var layEvent = obj.event; //获得 lay-event 对应的值
                    if (layEvent === 'detail') {
                        location.href = "/PersonnelMatters/SeeDimissionView?id=" + data.id;
                    } else if (layEvent === 'SubmitInfo') {
                        $.post("/CarryContract/UP?id=" + data.id + "&TId=8",
                            function(res) {
                                if (res == 3) {
                                    $.post("/PersonnelMatters/SubmitDimission?id=" + data.id,
                                        function(res) {
                                            if (res > 0) {
                                                layer.msg("提交成功!");
                                                location.reload();
                                            } else {
                                                layer.msg("状态修改失败!");
                                            }
                                        });
                                } else {
                                    layer.msg("提交失败!");
                                }
                            });

                    } else if (layEvent === 'edit') {
                        location.href = "/PersonnelMatters/BackDimissionView?id=" + data.id;
                    }
                });
        });


</script>

</body>
</html>



